﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;

namespace Model
{
    public class ContextUser
    {
        private string uesrcode;

        public string Uesrcode
        {
            get { return uesrcode; }
            set { uesrcode = value; }
        }

        private string empno;

        public string Empno
        {
            get { return empno; }
            set { empno = value; }
        }

        private string empname;

        public string Empname
        {
            get { return empname; }
            set { empname = value; }
        }

        private string depcode;

        public string Depcode
        {
            get { return depcode; }
            set { depcode = value; }
        }

        private string depname;

        public string Depname
        {
            get { return depname; }
            set { depname = value; }
        }

        private string comcode;

        public string Comcode
        {
            get { return comcode; }
            set { comcode = value; }
        }

        private string comname;

        public string Comname
        {
            get { return comname; }
            set { comname = value; }
        }

        private string supermk;

        public string Supermk
        {
            get { return supermk; }
            set { supermk = value; }
        }

        public static ContextUser Convert(DataTable dt)
        {
            if (null == dt || 0 == dt.Rows.Count)
                return null;

            DataRow dr = dt.Rows[0];
            ContextUser user = new ContextUser();
            if (!(dr["usercode"] is System.DBNull))
                user.uesrcode =  dr["usercode"].ToString();
            if (!(dr["empno"] is System.DBNull))
                user.empno = dr["empno"].ToString();
            if (!(dr["empname"] is System.DBNull))
                user.empname = (string)dr["empname"];
            if (!(dr["depno"] is System.DBNull))
                user.depcode = dr["depno"].ToString();
            if (!(dr["depname"] is System.DBNull))
                user.depname = (string)dr["depname"];
            if (!(dr["comcode"] is System.DBNull))
                user.comcode = dr["comcode"].ToString();
            if (!(dr["comname"] is System.DBNull))
                user.comname = (string)dr["comname"];
            if (!(dr["supermk"] is System.DBNull))
                user.Supermk = (string)dr["supermk"];

            return user;
        }
    }
}
